<template>
  <div>
    <van-nav-bar
      title="欢迎注册"
      right-text="去登录"
      @click-right="$router.push('/login')"
    />
    <div class="content">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          label="用户名"
          placeholder="用户名"
          maxlength="16"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          maxlength="18"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field name="type" label="单选框">
          <template #input>
            <van-radio-group v-model="type" direction="horizontal">
              <van-radio name="1">老板</van-radio>
              <van-radio name="2">消费者</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
<script>
import {reqRegister} from '@/api/index'
export default {
  data () {
    return {
      username: '',
      password: '',
      type:1
    }
  },
  methods:{
    async onSubmit(values) {
      console.log('submit', values);
      const res = await reqRegister(values)
      if(res.status === 200){
        this.$toast(res.msg)
        this.username=''
        this.password=''
      }
    },
  }
}
</script>
<style lang='less' scoped>
.content {
  margin: 100px 0 0 0;
}
</style>